<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@page import="java.util.*, java.sql.*" %>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Degree Discipline</title>
</head>
<body>

<% 

	String degreeUniversityParam = request.getParameter("degreeUniversity");
	String degreeUniversityIDParam = request.getParameter("universityID");
	String otherUniversityParam = request.getParameter("otherUniversity");

	Class.forName("org.postgresql.Driver");

	Connection connect = DriverManager.getConnection("jdbc:postgresql://localhost/tester?user=postgres&password=admin");
	Statement stmt = connect.createStatement();
	Statement stmt2 = connect.createStatement();
	ResultSet rset;
	ResultSet rset2;

	if(otherUniversityParam !=null)
	{
		
	
		rset = stmt.executeQuery("SELECT * FROM universities WHERE location='" + session.getAttribute("degreeCountrySes") + "' AND name='" + otherUniversityParam + "'");
		if ( !rset.next() )
		{
			stmt.execute("INSERT INTO universities (location, name) VALUES ('" + session.getAttribute("degreeCountrySes") + "', '" + otherUniversityParam + "')");
			rset2 = stmt2.executeQuery("SELECT last_value FROM universities_id_seq");
			while(rset2.next())
			{
				degreeUniversityIDParam = rset2.getString("last_value");
			}
		
		}
		
		
	
		degreeUniversityParam = otherUniversityParam;
	}

	
	session.setAttribute( "degreeUniversitySes", degreeUniversityParam );
	session.setAttribute( "degreeUniversityIDSes", degreeUniversityIDParam );
	
	
	PreparedStatement prepStmt;
	prepStmt = connect.prepareStatement("SELECT * FROM disciplines");
	rset = prepStmt.executeQuery();
	Vector majors = new Vector();
	Vector majorsID = new Vector();
	while(rset.next())
	{
		majorsID.add(rset.getString("id"));
		majors.add(rset.getString("name"));
	}
	
	
%>	
	
	<%= session.getAttribute("firstNameSes") %>
	<%= session.getAttribute("middleInitialSes") %>
	<%= session.getAttribute("lastNameSes") %><br>
	Citizen of <%= session.getAttribute("citizenSes") %><br>
	Resident of <%= session.getAttribute("residentSes") %><br>
	Address: <%= session.getAttribute("streetSes") %><br>
	City: <%= session.getAttribute("citySes") %><br>
	<%
	if( session.getAttribute("stateSes") != null )
	{ %>
		State: <%= session.getAttribute("stateSes") %><br>
	<%
	}
	else
	{ %>
		Country Code: <%= session.getAttribute("countryCodeSes") %><br>
		
	<% } %>
	Zip: <%= session.getAttribute("zipSes") %><br>
	Phone Number: (<%= session.getAttribute("areaCodeSes") %>) <%= session.getAttribute("phoneSes") %><br>
	<br>
	
	<%
	if ( session.getAttribute("permanentResident") != null)
	{ %>
		Domestic Status: <%= session.getAttribute("permanentResident") %><br>
	<% } %>
	
	Degree Obtained in: <%= session.getAttribute("degreeCountrySes") %><br>
	School: <%= session.getAttribute("degreeUniversitySes") %><br>
	<br>
	

	

	Please select your major<br>
	
	<form method="GET" action="9_moreDegrees.jsp">
	<%
	for(int i=0; i<majors.size(); i++)
	{ %>
		<input type="radio" name="degreeMajor" value="<%= majors.get(i) %>#majorID=<%= majorsID.get(i) %>"/> <%= majors.get(i) %><br>
	<% } %>
	
	<input type="radio" name="degreeMajor" value="other" />Other:<input type="text" name="otherMajor" /><br>
	
	
	Month and Year Degree was awarded (mm/yy)
	<input type="text" name="degreeDate"/><br>
	GPA <input type="text" name="degreeGPA"/><br>
	DegreeType<select name="degreeType">
		<option value="BS">BS</option>
		<option value="MS">MS</option>
		<option value="PHD">PHD</option>
	</select> <br>
	Upload a Transcript <input type="file" name="degreeFile"/>
	<br><input type="submit" value="Click to Submit"/>
	</form>
	
	
	



<br><br>

</body>
</html>